package com.softhis.rekrutacja.client.view;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.MarginData;
import com.extjs.gxt.ui.client.widget.layout.RowLayout;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.softhis.rekrutacja.client.presenter.MainPresenter.MainViewInterface;
import com.softhis.rekrutacja.client.view.widgets.impl.MyGxtButton;
import com.softhis.rekrutacja.client.view.widgets.impl.MyGxtToolBar;
import com.softhis.rekrutacja.client.view.widgets.interfaces.IButton;

/**
 * @author Sasak
 *
 */
public class MainView extends Viewport implements MainViewInterface {

	private LayoutContainer mainModuleWrapper = new LayoutContainer(new BorderLayout());
	private ContentPanel menuPanel = new ContentPanel();
	
	private LayoutContainer westSectionPanel = new LayoutContainer(new RowLayout());
	private BorderLayoutData westSectionData = new BorderLayoutData(LayoutRegion.WEST, 150);

	private ContentPanel northSectionPanel = new ContentPanel();
	private BorderLayoutData northSectionData = new BorderLayoutData(LayoutRegion.NORTH, 200);

	private ContentPanel centerSectionPanel = new ContentPanel();
	private Panel centerSectionScroll = new SimplePanel();
	private BorderLayoutData centerSectionData = new BorderLayoutData(LayoutRegion.CENTER);
	
	private VerticalPanel vert = new VerticalPanel();

	private MyGxtButton logoutButton = new MyGxtButton("Wyloguj");
	private MyGxtButton loginButton = new MyGxtButton("Zaloguj");
	private MyGxtButton newUserButton = new MyGxtButton("Nowe Konto");
	private MyGxtButton usersModuleButton = new MyGxtButton("Edycja Użytkowników");
	private MyGxtButton profileButton = new MyGxtButton("Twój Profil");
	private MyGxtButton mainPageButton = new MyGxtButton("Strona Główna");
	
	private MyGxtToolBar logoutToolBar = new MyGxtToolBar();
	private MyGxtToolBar loginToolBar = new MyGxtToolBar();
	private MyGxtToolBar newUserToolBar = new MyGxtToolBar();
	private MyGxtToolBar usersModuleToolBar = new MyGxtToolBar();
	private MyGxtToolBar profileToolBar = new MyGxtToolBar();
	private MyGxtToolBar mainPageToolBar = new MyGxtToolBar();
	
	/**
	 * constructor
	 */
	public MainView() {
		
		this.mainModuleWrapper.setStyleAttribute("background-color", "white");
		this.mainModuleWrapper.setWidth(1024);

		this.westSectionData.setMargins(new Margins(0, 10, 0, 0));
		this.westSectionPanel.setWidth(150);

		this.centerSectionPanel.setStyleAttribute("text-align", "left");
		this.centerSectionPanel.setFrame(true);
		this.centerSectionPanel.setHeaderVisible(true);
		this.centerSectionPanel.setScrollMode(Scroll.NONE);
		this.centerSectionPanel.setShadow(false);
		this.centerSectionPanel.add(this.centerSectionScroll);

		this.northSectionData.setMargins(new Margins(20, 0, 10, 0));
		this.northSectionPanel.setHeaderVisible(false);
		this.northSectionPanel.setBodyBorder(false);
		this.northSectionPanel.setFrame(false);
		this.northSectionPanel.setShadow(false);
		this.northSectionPanel.setBodyStyleName("SasakBaner");
		
		mainPageButton.setWidth(125);
		logoutButton.setWidth(125);
		loginButton.setWidth(125);
		newUserButton.setWidth(125);
		usersModuleButton.setWidth(125);
		profileButton.setWidth(125);
		
		mainPageToolBar.add(mainPageButton);
		logoutToolBar.add(logoutButton);
		loginToolBar.add(loginButton);
		newUserToolBar.add(newUserButton);
		usersModuleToolBar.add(usersModuleButton);
		profileToolBar.add(profileButton);
//		logoutToolBar.setVisible(false);
		
		menuPanel.setHeading("<center>MENU : </center>");
		
		menuPanel.add(mainPageToolBar);
		menuPanel.add(logoutToolBar);
		menuPanel.add(loginToolBar);
		menuPanel.add(newUserToolBar);
		menuPanel.add(usersModuleToolBar);
		menuPanel.add(profileToolBar);

		this.westSectionPanel.add(menuPanel, new MarginData(0, 0, 10, 0));
		
		this.mainModuleWrapper.add(this.northSectionPanel, northSectionData);
		this.mainModuleWrapper.add(this.centerSectionPanel, centerSectionData);
		this.mainModuleWrapper.add(this.westSectionPanel, westSectionData);
		
		// Auto scroll on page
		this.setScrollMode(Scroll.AUTO);

		vert.add(this.mainModuleWrapper);
		this.add(vert);
	}
	
	public void setLoggedIn(boolean b){
		this.loginToolBar.setVisible(!b);
		this.newUserToolBar.setVisible(!b);
		this.logoutToolBar.setVisible(b);
	}
	
	
	public void setCenterSection(Widget widget) {
		this.centerSectionScroll.clear();
		this.centerSectionScroll.add(widget);
		this.centerSectionPanel.layout();
	}

	public void maskCenterSection() {
        this.centerSectionPanel.mask("Wczytywanie");
    }

    public void unmaskCenterSection() {
        this.centerSectionPanel.unmask();
    }
       
    public void setMainHeader(String header) {
        this.centerSectionPanel.setHeading(header);
    }
	
    public IButton getLogoutB() {
		return logoutButton;
	}

    public IButton getLoginB() {
    	return loginButton;
    }
    
	public IButton getUsersModuleB() {
		return usersModuleButton;
	}

	public IButton getProfileB() {
		return profileButton;
	}
	
	public IButton getNewUserB(){
		return newUserButton;
	}
	
	public IButton getMainPageB(){
		return mainPageButton;
	}
}
